package cn.qm.service;


import cn.qm.dao.DepartmentMapper;
import cn.qm.pojo.Department;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* Created by shang-pc on 2018/5/15.
*/
@RestController
public class QmDepartmentClient {
    @Resource
    private DepartmentMapper departmentMapper;

    @RequestMapping(value = "/getDepartmentById", method = RequestMethod.POST)
    public Department getDepartmentById(@RequestParam Long id) throws Exception {
        return departmentMapper.getDepartmentById(id);
    }

    @RequestMapping(value = "/getDepartmentListByMap", method = RequestMethod.POST)
    public List<Department> getDepartmentListByMap(@RequestBody Map<String, Object> param) throws Exception {
        return departmentMapper.getDepartmentListByMap(param);
    }

    @RequestMapping(value = "/getDepartmentCountByMap", method = RequestMethod.POST)
    public Integer getDepartmentCountByMap(@RequestBody Map<String, Object> param) throws Exception {
        return departmentMapper.getDepartmentCountByMap(param);
    }

    @RequestMapping(value = "/qmtxAddDepartment", method = RequestMethod.POST)
    public Integer qmtxAddDepartment(@RequestBody Department department) throws Exception {
        department.setCreatedTime(new Date());
        return departmentMapper.insertDepartment(department);
    }

    @RequestMapping(value = "/qmtxModifyDepartment", method = RequestMethod.POST)
    public Integer qmtxModifyDepartment(@RequestBody Department department) throws Exception {
        department.setUpdatedTime(new Date());
        return departmentMapper.updateDepartment(department);
    }

    @RequestMapping(value = "/qmtxDeleteDepartmentById", method = RequestMethod.POST)
    public Integer qmtxDeleteDepartmentById(@RequestParam Long id) throws Exception {
        return departmentMapper.deleteDepartmentById(id);
    }

    @RequestMapping(value = "/queryDepartmentPageByMap", method = RequestMethod.POST)
    public Page<Department> queryDepartmentPageByMap(@RequestBody Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        return null;
    }
}
